#include <iostream>
#include <vector>
#include <algorithm>
#include "learn.h"
#include "algorithm_learn.h"
#include "map_learn.h"
#include "rapid_json_use.h"
#include "class_static_learn.h"
// #include "virtural_learn.h"

class MyClass
{
private:
    int m_a{};

public:
    void setValue(int a)
    {
        this->m_a = a;
    }
    void print()
    {
        std::cout << "print" << this->m_a << std::endl;
    }
};

void printVec(const std::vector<int> &vec)
{
    for (auto &item : vec)
    {
        std::cout << item << std::endl;
    }
}

void printVecV2(std::vector<int> &vec)
{
    for (auto it = vec.begin(); it != vec.end(); it++)
    {
        std::cout << *it << std::endl;
    }
}
int main()
{
    std::string s{"hello"};
    std::cout << "hello world" << std::endl;
    char str1[] = "hello world";
    std::string str2 = "hello world";

    std::cout << "str1" << str1 << std::endl;
    std::cout << "str2" << str2 << std::endl;

    template_func();

    std::vector<int> vec{1, 2, 3, 4, 5};
    size_t length{vec.size()};
    for (size_t i{0}; i < length; i++)
    {
        std::cout << "值" << vec[i] << std::endl;
    }

    MyClass my1;
    MyClass my2;
    my1.print();
    my2 = my1;
    my1.setValue(10);

    my1.print();
    my2.print();
    //-----vector操作----------------------------------------
    std::cout << "vector操作============================" << std::endl;
    std::vector<int> vec1{1, 2, 3, 4, 5};
    // 1.指定位置插入数
    vec1.insert(vec1.begin() + 2, 10); // 在索引2位置插入10
    // printVec(vec1);
    // 2.在尾部插入
    vec1.push_back(100);
    // printVec(vec1);

    // 删除尾部元素
    vec1.pop_back();
    printVec(vec1);

    // 删除指定位置元素
    vec1.erase(vec1.begin() + 2);                   // 删除索引2位置（也就是第三个元素）的元素，
    vec1.erase(vec1.begin() + 1, vec1.begin() + 3); // 删除索引1到3位置（也就是第二个、第三个元素）的元素，

    // 删除特定值（需结合算法库）#include <algorithm>
    vec1.erase(std::remove(vec1.begin(), vec1.end(), 3), vec1.end()); // 删除值为3的元素

    vec1.clear(); // 清空vector

    // 高级操作----------------------------
    std::cout << "高级操作============================" << std::endl;
    std::vector<int> vector1{1, 2, 3};
    std::vector<int> vector2{4, 5, 6};
    vector1.swap(vector2);
    printVec(vector1);
    printVec(vector2);

    // 内存释放
    std::vector<int>().swap(vector1);
    vector1.clear();
    vector1.shrink_to_fit();

    int x = 1;
    int y = 10;
    std::swap(x, y);
    std::cout << "x:" << x << " y:" << y << std::endl;

    std::vector<int> srot_vec{1, 5, 3, 2, 7};
    std::sort(srot_vec.begin(), srot_vec.end());
    for (auto &item : srot_vec)
    {
        std::cout << item << std::endl;
    }

    algorithm_learn();

    // map_learn();

    test_rapid_json();

    class_static_learn();

    std::cout << "virtural_learn============================" << std::endl;
    // virtural_learn();

    return 0;
}